#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/11/2 11:41
@desc
"""

import re
import os
from datax import exedatax

#
# retcode, stdout, stderr = exedatax("../job/teradata2hive.json")
#
#
# print("retcode:", retcode)
# print("stdout:", stdout.encode('utf-8'))
# print("stderr", stderr.encode('utf-8'))
#



stdout = '2018-11-05 18:11:33.086 [job-0] INFO  StandAloneJobContainerCommunicator - Total 0 records, 0 bytes | Speed 0B/s, 0 records/s | Error 0 records, 0 bytes |  All Task WaitWriterTime 0.000s |  All Task WaitReaderTime 0.000s | Percentage 0.00%\n2018-11-05 18:11:43.087 [job-0] INFO  StandAloneJobContainerCommunicator - Total 70 records, 15395 bytes | Speed 1.50KB/s, 7 records/s | Error 0 records, 0 bytes |  All Task WaitWriterTime 0.000s |  All Task WaitReaderTime 0.000s | Percentage 0.00%\n2018-11-05 18:11:53.090 [job-0] INFO  StandAloneJobContainerCommunicator - Total 70 records, 15395 bytes | Speed 0B/s, 0 records/s | Error 0 records, 0 bytes |  All Task WaitWriterTime 0.000s |  All Task WaitReaderTime 0.000s | Percentage 100.00%\n2018-11-05 18:11:53.253 [job-0] INFO  StandAloneJobContainerCommunicator - Total 70 records, 15395 bytes | Speed 513B/s, 2 records/s | Error 0 records, 0 bytes |  All Task WaitWriterTime 0.000s |  All Task WaitReaderTime 0.000s | Percentage 100.00%\n'

# stdlst = stdout.split(os.linesep)
stdlst = stdout.split('\n')

g = (i for i in stdlst if i)

totalcoll = list(g)[-1]

head = [i for i in totalcoll.split('|')][0]
print(head)

searchObj = re.search('(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}).*Total\s(\d+)\srecords.*?(\d+)\sbytes', head)
rtime = searchObj.group(1)
srecords = searchObj.group(2)
sbytes = searchObj.group(3)
print(rtime)
print(srecords)
print(sbytes)


